package com.guigu.servicesystem.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guigu.common_util.pojo.utils.Result;
import com.guigu.servicesystem.entity.TbLoginLog;
import com.guigu.servicesystem.service.TbLoginLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-07-08
 */
@RestController
@RequestMapping("/servicesystem/loginLog")
@CrossOrigin //解决跨域
public class TbLoginLogController {

    @Autowired
    private TbLoginLogService tbLoginLogService;

    //查询所有
    @GetMapping("findAll")
    public Result findAllTbLoginLog(){
        List<TbLoginLog> list = tbLoginLogService.list(null);
        return  Result.ok().data("items",list);
    }

    //条件+分页查询数据
    @PostMapping("findPage")
    public Result findPage(@RequestBody Map<String, Object> searchMap,Integer page,Integer size) {
        return tbLoginLogService.findPage(searchMap, page, size);
    }

    //根据id查询
    @GetMapping("findById")
    public Result getTbLoginLog(String id) {
        TbLoginLog tbLoginLog = tbLoginLogService.getById(id);
        return Result.ok().data("tbLoginLog",tbLoginLog);
    }

    //添加接口的方法
    @PostMapping("add")
    public Result addTbLoginLog(@RequestBody TbLoginLog tbLoginLog) {
        boolean save = tbLoginLogService.save(tbLoginLog);
        if(save) {
            return Result.ok();
        } else {
            return Result.error();
        }
    }
    //修改功能
    @PostMapping("update")
    public Result updateTbLoginLog(@RequestBody TbLoginLog tbLoginLog){
        boolean save = tbLoginLogService.updateById(tbLoginLog);
        if(save) {
            return Result.ok();
        } else {
            return Result.error();
        }
    }
    //逻辑删除
    @DeleteMapping("delete")
    public Result removeTbLoginLog(Integer id) {
        boolean flag = tbLoginLogService.removeById(id);
        if(flag) {
            return Result.ok();
        } else {
            return Result.error();
        }
    }
}

